<?php include_once("../ajax/ajaxReporte.php");
    header("Content-type: application/vnd.ms-excel; name='excel'");
    header("Content-Disposition: filename=OrdenCompraExcel.xls");
    header("Pragma: no-cache");
    header("Expires: 0");
    
    $num_doc = $_GET["num_doc"];
    
    function exportarOrdenCompra($num_doc){
        $rep = new ReporteBR();
        $result = $rep->listarOrdenCompra($num_doc);
        
        date_default_timezone_get("America/Lima");
        $fecha = date("d/m/Y - h:i:s A");
        
            $html.="<table>";
            $html.="<tr><td colspan='2' align='center'><h1>Orden de Compra</h1></td></tr>";
            $html.="<tr><td><b>Nro. Documento :</b></td><td width='90%'>".$num_doc."</td></tr>";
            $html.="<tr><td><b>Hasta :</b></td><td width='90%'>".$fecha."</td></tr>";
            $html.="<tr><td colspan='2'><hr></td></tr>";
            $html.="</table>";
            
            $html.= "<table border='1' >";
            $html.="<tr>";
            $html.="<th >Item</th>";
            $html.="<th >Producto</th>";
            $html.="<th >Cantidad</th>";
            $html.="<th >Codigo Proveedor</th>";
            $html.="<th >Proveedor</th>";
            $html.="</tr>";
            
            if(sizeof($result)==0){
                $html.="<tr><td colspan=5 align='center'>";
                $html.="No se encontraron registro";
                $html.="</td></tr>";
            }else{
                $count=0;
                foreach ($result as $res){
                    $count++;
                    
                    $html.="<tr style='font-family:verdana;font-size:11px;'>";
                    $html.="<td align='center'>$count</td>";
                    $html.="<td align='center'>$res->producto</td>";
                    $html.="<td align='center'>$res->cantidad</td>";
                    $html.="<td align='center'>$res->cod_proveedor</td>";
                    $html.="<td align='center'>$res->proveedor</td>";
                    $html.="</tr>";
                }
            }
            $html.="<tr><td colspan='5'><hr></td></tr>";
            $html.="<tr><td colspan='5' ><b>Numero de Registros : </b>$count</td></tr>";
            $html.="</table>";
            
            return $html;
    }
    
    exportarOrdenCompra($num_doc);
?>